package templateMethod;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*************************************************************
 *
 * 这是我们的咖啡类，用来煮咖啡
 *
 **********************************************************/
public class CoffeeWithHook extends CaffeineVeverageWithHook{
    //这是我们的咖啡冲泡法，直接取自训练手册


    /**
     * 以下每个方法都实现了算法中的一个步骤：著沸水/冲泡咖啡/把咖啡倒进杯子/加糖和奶
     */
    public void addCondiments() {
        System.out.println("Adding sugar and milk");
    }




    public void brew() {
        System.out.println("Dripping Coffee through filter");
    }


    //=============================================


    @Override
    boolean customerWantsCondiments() {
        String answer = getUserInput();

        return answer.toLowerCase().startsWith("y");
    }

    private String getUserInput() {

        String answer = null;

        System.out.println("Would you like milk and sugar with your coffee (y/n)?");

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        try {
            answer = in.readLine();

        } catch (IOException e) {
            System.err.println("IO error trying to read your answer");
        }
        if (answer == null){
            return "no";
        }
        return answer;
    }
}
